home *** CD-ROM | disk | FTP | other *** search
/ Stone Design / Stone Design.iso / Stone_Friends / Wave / WavesWorld / Source / Shaders / TexturingAndModeling:AProceduralApproach / DPShaders / DPBrickAntialiased.sl < prev    next >
Encoding:
Text File  |  1995-03-22  |  2.0 KB  |  72 lines

  1. #include "proctext.h"
  2.  
  3. #define BRICKWIDTH      0.25
  4. #define BRICKHEIGHT     0.08
  5. #define MORTARTHICKNESS 0.01
  6.  
  7. #define BMWIDTH         (BRICKWIDTH+MORTARTHICKNESS)
  8. #define BMHEIGHT        (BRICKHEIGHT+MORTARTHICKNESS)
  9. #define MWF             (MORTARTHICKNESS*0.5/BMWIDTH)
  10. #define MHF             (MORTARTHICKNESS*0.5/BMHEIGHT)
  11.  
  12. surface
  13. DPBrickAntialiased(
  14.     uniform float Ka = 1;
  15.     uniform float Kd = 1;
  16.     uniform color Cbrick = color (0.5, 0.15, 0.14);
  17.     uniform color Cmortar = color (0.5, 0.5, 0.5);
  18.      )
  19. {
  20.     color Ct;
  21.     point Nf;
  22.     float ss, tt, sbrick, tbrick, w, h;
  23.     float scoord = s;
  24.     float tcoord = t;
  25.     float swidth, twidth;
  26.  
  27.     Nf = normalize(faceforward(N, I));
  28.  
  29.     ss = scoord / BMWIDTH;
  30.     tt = tcoord / BMHEIGHT;
  31.  
  32.     if (mod(tt*0.5,1) > 0.5)
  33.         ss += 0.5;  /* shift alternate rows */
  34.  
  35.     /* BMRT can't handle anything other than s and t in Du and Dv, so... */
  36.     /* swidth = abs(Du(ss)*du) + abs(Dv(ss)*dv); */
  37.     /* twidth = abs(Du(tt)*du) + abs(Dv(tt)*dv); */
  38.     /* using alternative formulation... */
  39.     swidth = abs(Du(s)*du) + abs(Dv(s)*dv) / BMWIDTH;
  40.     twidth = abs(Du(t)*du) + abs(Dv(t)*dv) / BMHEIGHT;
  41.     tbrick = floor(tt); /* which brick? */
  42.     sbrick = floor(ss); /* which brick? */
  43.  
  44. #if 0
  45.     /* This is the simple antialiasing with "boxstep" */
  46.     ss -= sbrick;
  47.     tt -= tbrick;
  48.  
  49.     w = boxstep(MWF-swidth,MWF,ss)
  50.       - boxstep(1-MWF-swidth,1-MWF,ss);
  51.     h = boxstep(MHF-twidth,MHF,tt)
  52.       - boxstep(1-MHF-twidth,1-MHF,tt);
  53.  
  54. #else
  55.     /* This is the preferred antialiasing using integrals. */
  56. #define frac(x)        mod((x),1)
  57. #define sintegral(ss)  (floor(ss)*(1-2*MWF) + \
  58.                         max(0,frac(ss)-MWF))
  59. #define tintegral(tt)  (floor(tt)*(1-2*MHF) + \
  60.                         max(0,frac(tt)-MHF))
  61.  
  62.     w = (sintegral(ss+swidth) - sintegral(ss))/swidth;
  63.     h = (tintegral(tt+twidth) - tintegral(tt))/twidth;
  64. #endif
  65.  
  66.     Ct = mix(Cmortar, Cbrick, w*h);
  67.  
  68.     /* diffuse reflection model */
  69.     Oi = Os;
  70.     Ci = Os * Ct * (Ka * ambient() + Kd * diffuse(Nf));
  71. }
  72.